package com.tang.lts.core.nio.processor;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Tang
 * @classname WriteQueue
 * @description [  ]
 * @date 2022/5/15 15:16
 */
public class WriteQueue {

    private ConcurrentLinkedQueue<WriteRequest> queue = new ConcurrentLinkedQueue<>();
    private volatile ReentrantLock lock = new ReentrantLock();

    public void offer(WriteRequest request) {
        queue.add(request);
    }

    public WriteRequest peek() {
        return queue.peek();
    }

    public WriteRequest poll() {
        return queue.poll();
    }

    public boolean tryLock() {
        return lock.tryLock();
    }

    public void unlock() {
        lock.unlock();
    }

    public boolean isEmpty() {
        return queue.isEmpty();
    }


}